﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Data.OleDb;

namespace Web_HengliSeed.BLL
{
    public class AdminUser
    {
        /// <summary>
        /// 密码解锁
        /// </summary>
        /// <param name="strOldPass"></param>
        /// <param name="strNewPass"></param>
        /// <returns></returns>
        public static bool VateUpdatePass(out string strPass)
        {
            try
            {
                strPass = Common.GetMes.GetRandomNum(6);
                OleDbParameter[] parm = { new OleDbParameter("@NewPass", ClassFile.Function.PassEnCode(strPass)) };
                string strSql = " UPDATE T_CompanyInfo SET T_ManagePassWord=@NewPass ";
                return (ClassFile.AccessHelper.ExecuteNonQuery(ClassFile.AccessHelper.ConnectionString, strSql, parm) > 0) ? true : false;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="strOldPass"></param>
        /// <param name="strNewPass"></param>
        /// <returns></returns>
        public static bool VateUpdatePass(string strOldPass, string strNewPass)
        {
            try
            {
                OleDbParameter[] parm = {new OleDbParameter("@NewPass",ClassFile.Function.PassEnCode(strNewPass)),
                                         new OleDbParameter("@OldPass",ClassFile.Function.PassEnCode(strOldPass))};
                return (ClassFile.AccessHelper.ExecuteNonQuery(ClassFile.AccessHelper.ConnectionString, " UPDATE T_CompanyInfo SET T_ManagePassWord=@NewPass WHERE T_ManagePassWord=@OldPass ", parm) > 0) ? true : false;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 检测用户登录的用户名和密码
        /// </summary>
        /// <param name="strUserPass"></param>
        /// <returns></returns>
        public static bool CheckUserLogin(string strName, string strUserPass)
        {
            try
            {
                bool strReBool = false;
                string strRe = "0";
                OleDbParameter[] parm = { new OleDbParameter("@NewPass", ClassFile.Function.PassEnCode(strUserPass)) };
                if (strName == Common.GetMes.GetConfigAppValue("AdminName"))
                {
                    strRe = ClassFile.AccessHelper.ExecuteScalar(ClassFile.AccessHelper.ConnectionString, " SELECT COUNT(*) FROM T_CompanyInfo WHERE   T_ManagePassWord=@NewPass ", parm).ToString();
                    strReBool = (strRe == "0") ? false : true;
                }
                else
                {
                    strReBool = false;
                }
                SysLog.AddSysLog("【" + Common.GetMes.GetConfigAppValue("AdminName") + "】于{" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "}。登录后台。—" + ((strRe != "0") ? "【成功】" : "【失败】"), 1);
                return strReBool;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
